import numpy
import copy
class AVG:
    def __init__(self):
        self.servos1 = list(range(1, 4))
        self.result = None
        self.flag = 0
    def avg(self,servos):
        servos1 = copy.deepcopy(self.servos1)
        # print("servos1",servos1)
        if self.flag ==0:
            # self.servos1.append(servos)
            servos1[self.flag] = servos
            self.flag+=1
            # self.result.append(servos)
            # self.servos = servos
            # print("进入成功")
            self.result = servos
            self.servos1 = servos1
            return servos
        # print("self.servos",self.servos)
        # print("len(self.servos)__",len(self.servos))
        if self.flag<3:
            # print("111111111111")
            # self.servos1.append(servos)
            servos1[self.flag] = servos
            self.flag+=1
            # print("self.result",self.result,len(self.result))
            # print("servos",servos,len(servos))
            self.result = [[x1 + x2, y1+y2] for (x1, y1), (x2, y2) in zip(self.result, servos)]
            self.servos1 = servos1
            return [[int(x/self.flag),int( y/self.flag)] for x, y in self.result]
        # print("self.result",self.result)
        # print("#######################")
        # print("self.servos",self.servos)
        # self.result = [[x1 - x2, y1-y2] for (x1, y1), (x2, y2) in zip(self.result, self.servos[0])]
        # print
        # print(servos1[0])
        # print(len(servos1[0]))
        for i in range(14):
            self.result[i] = [self.result[i][0]-servos1[0][i][0],self.result[i][1]-servos1[0][i][1]]

        for i in range(self.flag-1):
            servos1[i] = servos1[i+1]
        servos1[self.flag-1] = servos


        for i in range(len(servos)):
            self.result[i] = [self.result[i][0]+servos[i][0],self.result[i][1]+servos[i][1]]
        # print("self.servos[9][0]",servos1[9][0])
        # print("servos",servos)
        # print("self.servos",len(servos1))
        # print("self.servos[0]",servos1[0])

        # self.servos1.pop(0)
        
        # print("self.result------------------",self.result)
        self.servos1 = servos1
        # print("result-------------",[[int(x/2),int( y/2)] for x, y in self.result])
        return [[int(x/3),int( y/3)] for x, y in self.result]
